from ..bot_plugin import Bot_plugin
from cqhttp import CQHttp
from bot_body import Bot_body
import logging
import colorful
import time

class Plugin_together_secs_count(Bot_plugin):
    def __init__(self, bot_body: Bot_body, name="together time count"):
        Bot_plugin.__init__(self, bot_body, name=name)

    def handle_msg(self, context):
        bot = self.bot
        if context['sender']['user_id'] in [892132762, 18627743328]:
            if context['raw_message'] in ['计时','我们在一起多久了','我们在一起多久啦']:
                elapsed_time = int(time.time() - 1507042980)
                days = elapsed_time // (3600*24)
                elapsed_time -= days*(3600*24)
                hours = elapsed_time // (3600)
                elapsed_time -= hours*3600
                minutes = elapsed_time // 60
                elapsed_time -= minutes*60
                seconds = elapsed_time
                echo_msg = "我们已经在一起{}天{}小时{}分钟{}秒啦！".format(
                    days, hours, minutes, seconds
                )
                bot.send(context, echo_msg)


